// 获取对象类型
const getType = (o) => Object.prototype.toString.call(o).toLocaleLowerCase().slice(1, -1).split(' ')[1];
// 是否字符串
const isString = (o) => getType(o) == 'string';
// 是否对象
const isObject = (o) => getType(o) == 'object';
let get = (url, param, loadingTip) => {
	let tip = isString(param) && !loadingTip ? param : loadingTip;
	tip && uni.showLoading({
		title: tip
	});
	return new Promise((resolve, reject) => {
		uni.$tn.http.get(url,{data:param}).then(res => {
			tip && uni.hideLoading();
			// resolve()之后，将会进入promise的组件内部的then回调，相当于返回true
			resolve(res)
		}).catch(err => {
			tip && uni.hideLoading();
			// reject()之后，将会进入promise的组件内部的catch回调，相当于返回false
			reject()
		})
	});
}
let post = (url, param, loadingTip) => {
	let tip = isString(param) && !loadingTip ? param : loadingTip;
	tip && uni.showLoading({
		title: tip
	});
	return new Promise((resolve, reject) => {
		uni.$tn.http.post(url,param).then(res => {
			tip && uni.hideLoading();
			// resolve()之后，将会进入promise的组件内部的then回调，相当于返回true
			resolve(res)
		}).catch(err => {
			tip && uni.hideLoading();
			if (err.msg) {
				uni.$tn.message.toast(err.msg)
			}
			// reject()之后，将会进入promise的组件内部的catch回调，相当于返回false
			reject()
		})
	});
}

export default {
	get,
	post
};
